
var Develop2 = {
	server: 'http://zwzx.syhg.gov.cn:8088/',
	server_path: 'http://zwzx.syhg.gov.cn:8088/',
	server_name: 'http://zwzx.syhg.gov.cn:8088/index.php/Api/',
};

var realVersion = Develop2;
var SERVER = realVersion.server;
var SERVER_PATH = realVersion.server_path;
var SERVER_NAME = realVersion.server_name;

var common = null;
$(function(){


	common = {
		
		setLocVal: function(name, value) {
			localStorage[name] = value;
		},
		getLocVal: function(name) {
			var result = localStorage[name];
			if(typeof(result) == "undefined") {
				result = "";
			}
			return result;
		},
		clearLocVal: function(key) {
			if(!key) {
				localStorage.clear();
			} else {
				localStorage.removeItem(key);
			}

		},
		removeHTMLTag: function(str) {
			if(typeof(str) == 'string') {
				str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
				str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
				//str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
				str = str.replace(/&nbsp;/ig, ''); //去掉&nbsp;
				return str;
			} else {
				return '';
			}

		},
		JsonPost: function(params, func) {
			
			var oauth = {
				user_id:common.getLocVal("userId")
			}
			if(typeof params.data === 'undefined') {
				params.data = {};
			}
			mui.extend(true, params.data, oauth);
			console.log(JSON.stringify(params));
			
			$.ajax({
				url: SERVER_NAME + params.url,
				type: "post",
				dataType: "json",
				data: params.data,
				success: function(data){
					if(data.code == 200){
						func(data.data);
					}else{
						func(false);
						common.toast(data.msg);
					}
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(params.url + type);
					
					//common.toast("哎呀~网络不给力~~");
				}
			});
			
		},
		redirect: function (url) {
            window.location.href = url;
        },
		alert: function(title, text, func) {
			mui.alert( text, title, "确定", func, 'div' );
			//plus.nativeUI.alert(text, func, title, "确定",'div');
		},
		confirm: function(title, text, func) {
			
			mui.confirm( text, title, ['确定', '取消'], func, 'div' );
			//plus.nativeUI.confirm(text, func, title, ['确定', '取消']);
		},
		confirms: function(title, text, btns, func) {
			btns = btns || ['确定', '取消'];
			
			mui.confirm( text, title, btns, func, 'div' );
			//plus.nativeUI.confirm(text, func, title, btns);
		},
		toast: function(text) {
			mui.toast(text,'div');
			//plus.nativeUI.toast(text);
		},
		subLastString: function(str) {
			var s = str.substring(0, str.length - 1);
			return s;
		},
		loading: function(title, text) {
			mui.showLoading(title,"div");
			//plus.nativeUI.showWaiting(title);
		},
		closeLoading: function() {
			mui.hideLoading();
			//plus.nativeUI.closeWaiting();
		},
		isEmptyObject: function(obj) {
			//common.alert("提示",JSON.stringify(obj),function(){return false;});
			if(JSON.stringify(obj) === '{}') {
				return true;
			}
			return false;
		},
		isEmptyArray: function(obj) {
			if(JSON.stringify(obj) === '[]') {
				return true;
			}
			return false;
		},
		/**
		 * 回到应用的首页
		 */
		goBackRoot: function() {
			var wvs = plus.webview.all();
			var root = plus.webview.getLaunchWebview();
			for(var i = 0; i < wvs.length; i++) {

				if(wvs[i].getURL() == root.getURL()) {
					root.reload();
					continue;
				}
				wvs[i].close("none");
			}
		},
		isEmpty: function(str) {
			if(str == "" || str == " ") {
				return false;
			} else {
				return true;
			}
		},
		isTelphone: function(mobile) {
			var myreg = /^((13|14|15|17|18)+\d{9})$/;
			if(!myreg.test(mobile)) {
				return false;
			} else {
				return true;
			}
		},
		inArray: function(value, array) {
			var status = false;
			for(var key in array) {
				if(array[key] == value) {
					status = true;
				}
			}
			return status;
		},
		getTimeStamp: function() {
			var timestamp = Date.parse(new Date());
			return timestamp / 1000;
		}
		
	}
})
